package com.qipay.baas.mapper;

import com.qipay.baas.model.SpChannel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface SpChannelMapper {
    @Delete({
        "delete from sp_channel",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into sp_channel (sp_id, channel_type, ",
        "fee_recharge, `state`, ",
        "update_date, create_date,quota)",
        "values (#{spId,jdbcType=BIGINT}, #{channelType,jdbcType=TINYINT}, ",
        "#{feeRecharge,jdbcType=DECIMAL}, #{state,jdbcType=TINYINT}, ",
        "#{updateDate,jdbcType=TIMESTAMP}, #{createDate,jdbcType=TIMESTAMP}, #{quota, jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(SpChannel record);

    @InsertProvider(type=SpChannelSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insertSelective(SpChannel record);

    @Select({
        "select",
        "id, sp_id, channel_type, fee_recharge, `state`, update_date, create_date, quota",
        "from sp_channel",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="sp_id", property="spId", jdbcType=JdbcType.BIGINT),
        @Result(column="channel_type", property="channelType", jdbcType=JdbcType.TINYINT),
        @Result(column="fee_recharge", property="feeRecharge", jdbcType=JdbcType.DECIMAL),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="update_date", property="updateDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="quota", property="quota", jdbcType=JdbcType.VARCHAR)
    })
    SpChannel selectByPrimaryKey(Integer id);

    @UpdateProvider(type=SpChannelSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SpChannel record);

    @Update({
        "update sp_channel",
        "set sp_id = #{spId,jdbcType=BIGINT},",
          "channel_type = #{channelType,jdbcType=TINYINT},",
          "fee_recharge = #{feeRecharge,jdbcType=DECIMAL},",
          "`state` = #{state,jdbcType=TINYINT},",
          "update_date = #{updateDate,jdbcType=TIMESTAMP},",
          "create_date = #{createDate,jdbcType=TIMESTAMP},",
          "quota = #{quota,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(SpChannel record);
}